package com.pig4cloud.pig.mt.manage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.mt.entity.WxArticle;
import com.pig4cloud.pig.mt.service.WxArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 文章
 *
 * @author niefy
 * @email niefy@qq.com
 * @date 2019-11-12 18:30:16
 */
@RestController
@RequestMapping("/manage/article")
@Api(value = "/manage/article", tags = "CMS文章中心管理")
public class ArticleManageController {
    @Autowired
    private WxArticleService articleService;

    /**
     * 列表
     */
	@ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/list")
	@PreAuthorize("@pms.hasPermission('mt_wxarticle_get')" )
    public R list(@RequestParam Map<String, Object> params) {
        IPage page = articleService.queryPage(params);
        return R.ok(page);
    }


    /**
     * 信息
     */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/info/{id}")
	@PreAuthorize("@pms.hasPermission('mt_wxarticle_get')" )
    public R info(@PathVariable("id") Integer id) {
        WxArticle article = articleService.getById(id);
        return R.ok(article);
    }

    /**
     * 保存
     */
	@ApiOperation(value = "新增CMS文章", notes = "新增CMS文章")
	@SysLog("新增CMS文章")
    @PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mt_wxarticle_add')" )
    public R save(@RequestBody WxArticle article) {
        articleService.save(article);

        return R.ok();
    }

    /**
     * 删除
     */
	@ApiOperation(value = "通过id删除CMS文章", notes = "通过id删除CMS文章")
	@SysLog("通过id删除CMS文章")
    @DeleteMapping("/delete")
	@PreAuthorize("@pms.hasPermission('mt_wxarticle_del')" )
    public R delete(@RequestBody Integer[] ids) {
        articleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
